//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.quickserver.net.qsadmin.gui;

import java.awt.Container;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import org.quickserver.swing.JFrameUtilities;

public class LoginDialog extends JDialog {
    private JPanel topPanel;
    private JPanel ipPanel;
    private JPanel authPanel;
    private JPanel buttonPanel;
    private JLabel productName;
    private JLabel ipLabel;
    private JTextField ipField;
    private JLabel portLabel;
    private JTextField portField;
    private JLabel loginLabel;
    private JTextField loginField;
    private JLabel passwordLabel;
    private JPasswordField passwordField;
    private JButton loginButton;
    private JButton cancelButton;
    private String statusTxt1 = "<html><font style=\"font-size:15pt;color:#535353\"><b>";
    private String statusTxt2 = "</b></font>";
    private GridBagConstraints gbc = new GridBagConstraints();
    private String[] values = new String[4];
    private boolean isOk = false;

    public LoginDialog(Frame parent) {
        super(parent, "QSAdmin Login");
        this.productName = new JLabel(this.statusTxt1 + "QSAdmin Login" + this.statusTxt2, 0);
        this.ipLabel = new JLabel("IP Address");
        this.ipField = new JTextField("127.0.0.1");
        this.portLabel = new JLabel("Port");
        this.portField = new JTextField("9876");
        this.loginLabel = new JLabel("Login");
        this.loginField = new JTextField("Admin");
        this.passwordLabel = new JLabel("Password");
        this.passwordField = new JPasswordField("QsAdm1n");
        this.loginButton = new JButton("<html><font style=\"font-size:10pt;color:#535353\"><b>Login</b></font>");
        this.loginButton.setMnemonic('L');
        this.cancelButton = new JButton("<html><font style=\"font-size:10pt;color:#535353\"><b>Cancel</b></font>");
        this.cancelButton.setMnemonic('C');
        this.cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LoginDialog.this.hide();
            }
        });
        this.ipField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LoginDialog.this.portField.requestFocus();
            }
        });
        this.portField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LoginDialog.this.loginField.requestFocus();
            }
        });
        this.loginField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LoginDialog.this.passwordField.requestFocus();
            }
        });
        ActionListener loginAl = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LoginDialog.this.isOk = false;
                if (LoginDialog.this.ipField.getText().equals("")) {
                    LoginDialog.this.showError("Blank IP Address");
                } else if (LoginDialog.this.portField.getText().equals("")) {
                    LoginDialog.this.showError("Blank Port Number");
                } else {
                    try {
                        Integer.parseInt(LoginDialog.this.portField.getText());
                    } catch (Exception var3) {
                        LoginDialog.this.showError("Bad Port Number.");
                        return;
                    }

                    if (LoginDialog.this.loginField.getText().equals("")) {
                        LoginDialog.this.showError("Blank Login");
                    } else {
                        char[] px = LoginDialog.this.passwordField.getPassword();
                        if (px != null && px.length != 0) {
                            char[] p = null;
                            LoginDialog.this.hide();
                            LoginDialog.this.isOk = true;
                        } else {
                            LoginDialog.this.showError("Blank password");
                        }
                    }
                }
            }
        };
        this.loginButton.addActionListener(loginAl);
        this.passwordField.addActionListener(loginAl);
        this.cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LoginDialog.this.hide();
                LoginDialog.this.isOk = false;
            }
        });
        Container cp = this.getContentPane();
        this.topPanel = new JPanel();
        this.topPanel.setLayout(new GridBagLayout());
        this.gbc.insets = new Insets(2, 2, 2, 2);
        this.gbc.weighty = 0.0D;
        this.gbc.weightx = 0.0D;
        this.gbc.gridx = 0;
        this.gbc.gridy = 0;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.anchor = 10;
        this.gbc.fill = 0;
        this.topPanel.add(this.productName, this.gbc);
        this.ipPanel = new JPanel();
        this.ipPanel.setLayout(new GridBagLayout());
        this.gbc.gridx = 0;
        this.gbc.gridy = 0;
        this.gbc.weightx = 0.0D;
        this.gbc.weighty = 0.0D;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.anchor = 17;
        this.gbc.fill = 0;
        this.ipPanel.add(this.ipLabel, this.gbc);
        this.gbc.gridx = 1;
        this.gbc.gridy = 0;
        this.gbc.weightx = 1.0D;
        this.gbc.fill = 1;
        this.ipPanel.add(this.ipField, this.gbc);
        this.gbc.gridx = 0;
        this.gbc.gridy = 1;
        this.gbc.weightx = 0.0D;
        this.gbc.fill = 0;
        this.ipPanel.add(this.portLabel, this.gbc);
        this.gbc.gridx = 1;
        this.gbc.gridy = 1;
        this.gbc.weightx = 1.0D;
        this.gbc.fill = 1;
        this.ipPanel.add(this.portField, this.gbc);
        this.ipPanel.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), "Location"));
        this.authPanel = new JPanel();
        this.authPanel.setLayout(new GridBagLayout());
        this.gbc.gridx = 0;
        this.gbc.gridy = 0;
        this.gbc.weightx = 0.0D;
        this.gbc.weighty = 0.0D;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.anchor = 17;
        this.gbc.fill = 0;
        this.authPanel.add(this.loginLabel, this.gbc);
        this.gbc.gridx = 1;
        this.gbc.gridy = 0;
        this.gbc.weightx = 1.0D;
        this.gbc.fill = 1;
        this.authPanel.add(this.loginField, this.gbc);
        this.gbc.gridx = 0;
        this.gbc.gridy = 1;
        this.gbc.weightx = 0.0D;
        this.gbc.fill = 0;
        this.authPanel.add(this.passwordLabel, this.gbc);
        this.gbc.gridx = 1;
        this.gbc.gridy = 1;
        this.gbc.weightx = 1.0D;
        this.gbc.fill = 1;
        this.authPanel.add(this.passwordField, this.gbc);
        this.authPanel.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), "Authentication"));
        this.buttonPanel = new JPanel();
        this.buttonPanel.setLayout(new GridBagLayout());
        this.gbc.gridx = 0;
        this.gbc.gridy = 0;
        this.gbc.weightx = 0.0D;
        this.gbc.weighty = 0.0D;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.anchor = 10;
        this.gbc.fill = 0;
        this.buttonPanel.add(this.loginButton, this.gbc);
        this.gbc.gridx = 1;
        this.buttonPanel.add(this.cancelButton, this.gbc);
        cp.setLayout(new GridBagLayout());
        this.gbc.gridx = 0;
        this.gbc.gridy = 0;
        this.gbc.weightx = 1.0D;
        this.gbc.weighty = 1.0D;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.anchor = 10;
        this.gbc.fill = 2;
        cp.add(this.topPanel, this.gbc);
        this.gbc.fill = 1;
        this.gbc.gridy = 1;
        cp.add(this.ipPanel, this.gbc);
        this.gbc.fill = 1;
        this.gbc.gridy = 2;
        cp.add(this.authPanel, this.gbc);
        this.gbc.fill = 2;
        this.gbc.gridy = 3;
        cp.add(this.buttonPanel, this.gbc);
        this.pack();
        this.setSize(240, 250);
        this.setResizable(false);
        this.setModal(true);
        JFrameUtilities.centerWindow(this);
    }

    private void showError(String msg) {
        JOptionPane.showMessageDialog(this, msg, "Error", 0);
    }

    public String[] getValues() {
        this.values[0] = this.ipField.getText();
        this.values[1] = this.portField.getText();
        this.values[2] = this.loginField.getText();
        this.values[3] = new String(this.passwordField.getPassword());
        return this.values;
    }

    public boolean isOk() {
        return this.isOk;
    }
}
